package com.lsp.microuser.user.controller;

import com.lsp.microcommon.annotation.NoLogin;
import com.lsp.microcommon.common.CommonResult;
import com.lsp.microuser.user.params.LoginParam;
import com.lsp.microuser.user.params.RegisterParam;
import com.lsp.microuser.user.service.LoginService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
//实际开发中，如果既有后台也有app端，一般需要在控制器的路径中，体现出是给哪个端使用的接口
@RestController
@RequestMapping("/app/user")
public class LoginController {
    @Resource
    private LoginService loginService;

    @NoLogin
    @PostMapping("/login")
    public CommonResult login(@RequestBody LoginParam param){
        return CommonResult.success(loginService.login(param));
    }

    @NoLogin
    @GetMapping("/code")
    public CommonResult sendCode(String phone){
        String code = loginService.sendCode(phone);
        return CommonResult.success(code);
    }


    @NoLogin
    @PostMapping("/register")
    public CommonResult register(@RequestBody RegisterParam param){
        loginService.addUser(param);
        return CommonResult.success();
    }


}
